home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / WWSample.m < prev    next >
Encoding:
Text File  |  1995-03-29  |  5.9 KB  |  183 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5.  
  6. #import "WWSample.h"
  7.  
  8. @implementation WWSample
  9.  
  10. - setData:newData timestamp:(float)floatTime generator:(const char *)genName weight:(float)newWeight
  11. {
  12.    if (data)
  13.    {  if (freeData)
  14.       {  [data free];
  15.       }
  16.    }
  17.    data = newData;
  18.    freeData = YES;
  19.  
  20.    timestamp = floatTime;  // this obviously should be an object, but for now...
  21.  
  22.    if (generatorName)
  23.    {  free(generatorName);
  24.    }
  25.    if (genName)
  26.    {  generatorName = NXCopyStringBuffer(genName);
  27.    }
  28.    else
  29.    {  generatorName = NULL;
  30.    }
  31.    weight = newWeight;
  32.  
  33.    return self;
  34. }
  35.  
  36. - free
  37. {
  38.   //NXLogError("WWSample %p at time %f being free'ed\n", self, timestamp);
  39.   //NXLogError("WWSample freeing data %s %p\n", [[data class] name], data);
  40.   if ([self freeData])
  41.   {  [data free];
  42.   }
  43.   return [super free];
  44. }
  45.  
  46. - (float)timestamp { return timestamp; }
  47. - sample { return data; }
  48. - data { return data; }
  49.  
  50. - setFreeData:(BOOL)flag { freeData = flag;  return self; }
  51. - (BOOL)freeData { return freeData; }
  52.  
  53. - (float)weight { return weight; }
  54. - setWeight:(float)newWeight { weight = newWeight; return self; }
  55.  
  56. - (int)generatorCount { return 1; }
  57.  
  58. - (const char *)generatorName { return (const char *)generatorName; }
  59.  
  60.  
  61. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  62. {
  63.    //int  i;
  64.  
  65.  
  66.    //for (i = 0; i < tab; i++)
  67.    //{  NXPrintf(stream, "\t");
  68.    //}
  69.  
  70.    if (generatorName)
  71.    {  NXPrintf(stream, "{{%s} %f {", generatorName, weight);
  72.    }
  73.    else
  74.    {  NXPrintf(stream, "{{} %f {", weight);
  75.    }
  76.    [data writeEve:stream atTabLevel:0];  // kinda gross, but we've already moved the cursor where we want...
  77.    NXPrintf(stream, "}} ");
  78.  
  79.    return self;
  80. }
  81.  
  82. - oldWrite3DTextScene:(NXStream *)stream atTabLevel:(int)tab index:(int)index time:(float)time
  83. {
  84.    int  i;
  85.  
  86.  
  87.    for (i = 0; i < tab; i++)
  88.    {  NXPrintf(stream, "\t");
  89.    }
  90.  
  91.    NXPrintf(stream, "startShape %s; ", [[data class] name]);
  92.    // need tab
  93.    // need index (position in current list)
  94.    NXPrintf(stream, "set __text__(colorTime%f) {1 1 1};", time);
  95.    NXPrintf(stream, "set __text__(colorSurface%f) plastic;", time);
  96.    NXPrintf(stream, "EveCmd {Color $__text__(colorTime%f) }; ", time); // to make animation easy
  97.    NXPrintf(stream, "EveCmd {Surface $__text__(colorSurface%f)}; ", time); // to make animation easy
  98.  
  99.    NXPrintf(stream, 
  100.         "EveCmd {Translate [expr { %d * $__text__(tabLength)}] ", tab);
  101.    NXPrintf(stream, 
  102.             "[expr {$__text__(spacingFactor) * %d * $__text__(spacing) * $__text__(fontSize)}] ", index);
  103.    NXPrintf(stream, 
  104.             "[expr {$__text__(sampleOffset) + ($__text__(timeFactor) * %f)}]};\n", time); 
  105.    NXPrintf(stream, "  EveCmd {WW3DText $__text__(fontName) $__text__(fontSize) {");
  106.      [data writeEve:stream atTabLevel:tab];
  107.    NXPrintf(stream, "} left;}\n");
  108.   NXPrintf(stream, "endShape;\n");
  109.  
  110.   return self;
  111. }
  112.  
  113. - write3DTextScene:(NXStream *)stream atTabLevel:(int)tab index:(int)index time:(float)time until:(float)lastTime
  114. {
  115.    int  i;
  116.  
  117.  
  118.    for (i = 0; i < tab; i++)
  119.    {  NXPrintf(stream, "\t");
  120.    }
  121.  
  122.    NXPrintf(stream, "startShape %s; ", [[data class] name]);
  123.    // need tab
  124.    // need index (position in current list)
  125.    NXPrintf(stream, "set __text__(colorTime%f) {1 1 1};", time);
  126.    NXPrintf(stream, "set __text__(colorSurface%f) plastic;", time);
  127.    NXPrintf(stream, "EveCmd {Color $__text__(colorTime%f) }; ", time); // to make animation easy
  128.    NXPrintf(stream, "EveCmd {Surface $__text__(colorSurface%f)}; ", time); // to make animation easy
  129.  
  130.    NXPrintf(stream, 
  131.         "EveCmd {Translate [expr { %d * $__text__(tabLength)}] ", tab);
  132.    NXPrintf(stream, 
  133.             "[expr {$__text__(spacingFactor) * %d * $__text__(spacing) * $__text__(fontSize)}] ", index);
  134.    NXPrintf(stream, 
  135.             "[expr {$__text__(sampleOffset) + ($__text__(timeFactor) * %f)}]};\n", time); 
  136.    NXPrintf(stream, "  EveCmd {WW3DText $__text__(fontName) $__text__(fontSize) {");
  137.      [data writeEve:stream atTabLevel:tab];
  138.    NXPrintf(stream, "} left;} {\\\n");
  139.    // okay, now we want to put a time stamped sample of this guy out there
  140.    // if the current timestamp isn't 0.0, we need to stick a blank a sample at 0.0
  141.  
  142.    // so here's the deal:
  143.   
  144.    if (timestamp == 0.0)
  145.    { if ([self generatorName])
  146.      {  NXPrintf(stream, "          {0.000000 { {{%s} %f {WW3DText {Helvetica} 10.0 {", [self generatorName], [self weight]);
  147.      }
  148.      else
  149.      {  NXPrintf(stream, "          {0.000000 { {{} %f {WW3DText {Helvetica} 10.0 {", [self weight]);
  150.      }
  151.        [data writeEve:stream atTabLevel:tab];
  152.       NXPrintf(stream, "} left;}} }} \\\n");
  153.    }
  154.    else
  155.    {  if ([self generatorName])
  156.       {  NXPrintf(stream, "          {0.000000 { {{%s} %f {WW3DText {Helvetica} 10.0 {} left;}} }} \\\n", [self generatorName], [self weight]);
  157.          NXPrintf(stream, "          {%f { {{%s} %f {WW3DText {Helvetica} 10.0 {", [self timestamp], [self generatorName], [self weight]);
  158.       }
  159.       else
  160.       {  NXPrintf(stream, "          {0.000000 { {{} %f {WW3DText {Helvetica} 10.0 {} left;}} }} \\\n", [self weight]);
  161.          NXPrintf(stream, "          {%f { {{} %f {WW3DText {Helvetica} 10.0 {", [self timestamp], [self weight]);
  162.       }
  163.        [data writeEve:stream atTabLevel:tab];
  164.       NXPrintf(stream, "} left;}} }} \\\n");
  165.    }
  166.  
  167.    // this takes care of "turning off" this sample at the appropriate time, as long as it's not the last
  168.    if ((timestamp != lastTime) && (lastTime != -1))  // -1 is magic for it being the last...
  169.    {  NXPrintf(stream, "          {%f { {{%s} %f {WW3DText {Helvetica} 10.0 {} left;}} }} \\\n", (lastTime * .999), [self generatorName], [self weight]);
  170.    }
  171.    NXPrintf(stream, "         }\n");
  172.  
  173.   NXPrintf(stream, "endShape;\n");
  174.  
  175.   return self;
  176. }
  177.  
  178. // boy, this is dumb... This is to get around the stupid warnings from the compiler - ask wave for details
  179. - class { return [super class]; }
  180. - (BOOL) conformsTo: (Protocol *)aProtocolObject { return [super conformsTo:aProtocolObject]; }
  181.  
  182. @end
  183.